const connection = require("../app/database.js")

class UserService {
  // 创建用户
  async create(user) {
    // 1.获取账号密码
    const { username, password } = user
    // 2.预处理语句
    const statement = "INSERT INTO `user` (username, password) VALUES (?, ?);"
    // 3.执行sql语句
    const [result] = await connection.execute(statement, [username, password])
    return result
  }

  // 查找用户是否存在
  async findUserByName(username) {
    const statement = "SELECT * FROM `user` WHERE username = ?"
    const [result] = await connection.execute(statement, [username])
    return result
  }
}

module.exports = new UserService()
